import 'package:flutter/material.dart';

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: '伴学',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        fontFamily: 'ZCOOLKuaiLe', // 儿童手写风格字体
        textTheme: const TextTheme(
          headlineSmall: TextStyle(fontSize: 24, fontWeight: FontWeight.bold, color: Colors.purple),
          bodyLarge: TextStyle(fontSize: 20, color: Colors.deepPurple),
        ),
        elevatedButtonTheme: ElevatedButtonThemeData(
          style: ElevatedButton.styleFrom(
            minimumSize: const Size(120, 60), // 大按钮尺寸
            shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
            backgroundColor: Colors.orangeAccent,
            textStyle: const TextStyle(fontSize: 20),
          ),
        ),
      ),
      initialRoute: '/',
      routes: {
        '/': (context) => const HomePage(),
        '/learning': (context) => const LearningCenterPage(),
        '/content': (context) => const ContentPage(),
        '/practice': (context) => const PracticePage(),
        '/settings': (context) => const SettingsPage(),
      },
    );
  }
}

// 主页 - 年龄选择
class HomePage extends StatelessWidget {
  const HomePage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('选择年龄段')),
      body: ListView(
        children: [
          _buildAgeCard(context, '2-3岁'),
          _buildAgeCard(context, '4-5岁'),
          _buildAgeCard(context, '小学'),
          _buildAgeCard(context, '初中'),
          _buildAgeCard(context, '高中'),
        ],
      ),
    );
  }

  Widget _buildAgeCard(BuildContext context, String age) {
    return Card(
      elevation: 8,
      shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
      color: Colors.lightBlue[100],
      child: InkWell(
        borderRadius: BorderRadius.circular(20),
        onTap: () => Navigator.pushNamed(context, '/learning'),
        child: Padding(
          padding: const EdgeInsets.all(20),
          child: Center(
            child: Text(
              age,
              style: const TextStyle(fontSize: 24, fontWeight: FontWeight.bold, color: Colors.deepPurple),
            ),
          ),
        ),
      ),
    );
  }
}

// 学习中心
class LearningCenterPage extends StatelessWidget {
  const LearningCenterPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('学习模块')),
      body: GridView.count(
        crossAxisCount: 2,
        children: [
          _buildModuleCard(context, '汉字', Icons.text_format),
          _buildModuleCard(context, '拼音', Icons.phonelink_ring),
          _buildModuleCard(context, '古诗', Icons.menu_book),
          _buildModuleCard(context, '短文', Icons.article),
          _buildModuleCard(context, '长文', Icons.library_books),
          _buildModuleCard(context, '英语', Icons.language),
        ],
      ),
    );
  }

  Widget _buildModuleCard(BuildContext context, String title, IconData icon) {
    return Card(
      elevation: 8,
      shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
      color: Colors.pink[100],
      child: InkWell(
        borderRadius: BorderRadius.circular(20),
        onTap: () => Navigator.pushNamed(context, '/content'),
        child: Padding(
          padding: const EdgeInsets.all(16),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Icon(icon, size: 50, color: Colors.deepOrange),
              const SizedBox(height: 15),
              Text(
                title,
                style: const TextStyle(fontSize: 20, fontWeight: FontWeight.bold, color: Colors.deepPurple),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

// 内容展示页
class ContentPage extends StatelessWidget {
  const ContentPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('学习内容'),
        actions: [
          IconButton(
            icon: const Icon(Icons.settings),
            onPressed: () => Navigator.pushNamed(context, '/settings'),
          ),
        ],
      ),
      body: const Center(child: Text('这里是具体学习内容')),
      floatingActionButton: FloatingActionButton(
        child: const Icon(Icons.mic),
        onPressed: () => Navigator.pushNamed(context, '/practice'),
      ),
    );
  }
}

// 跟读练习页
class PracticePage extends StatelessWidget {
  const PracticePage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('跟读练习')),
      body: const Center(child: Text('跟读功能将在这里实现')),
    );
  }
}

// 设置页
class SettingsPage extends StatelessWidget {
  const SettingsPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('设置')),
      body: ListView(
        children: const [
          ListTile(title: Text('账号管理')),
          ListTile(title: Text('学习进度')),
          ListTile(title: Text('内容难度')),
          ListTile(title: Text('家长控制')),
        ],
      ),
    );
  }
}
